<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Orderdate_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 返回订单日期的数量
	 */
	public function count_dates(){
		$query = $this->db->get('t_orderdate');
		return $query->num_rows();
	}
	/*
	 * 根据分页信息得到订单日期信息
	 */
	public function get_dates($page,$offset){
		$this->db->limit($page, $offset);
		$query = $this->db->get('t_orderdate');
		return $query->result_array();
	}
	/*
	 * 根据订单日期ID得到订单日期信息
	 */
	public function load($id){
		$query = $this->db->get_where('t_orderdate',array('id' => $id));
		if ($row = $query->row_array()){
			return $row;
		}
		return array();
	}
	/*
	 * 添加订单日期信息
	 */
	public function create($date){
		$this->db->insert('t_orderdate', $date);
		return $this->db->insert_id();
	}
	/*
	 * 更新订单日期信息
	 */
	public function update($id,$date){
		$this->db->where('id', $id);
		$this->db->update('t_orderdate', $date);
		return $this->db->affected_rows()>0;
	}
	/*
	 * 删除订单日期信息
	 */
	public function delete($id){
		$this->db->where('id', $id);
		$this->db->delete('t_orderdate');
		return $this->db->affected_rows()>0;
	}
	/*
	 *根据日期和类型查找
	 */
	public function find_by_date($date,$type){
		$this->db->where('date', $date);
		$this->db->where('type', $type);
		$query = $this->db->get('t_orderdate');
		return $query->row_array();
	}
}